package tech.yunland.shop.domain.model;

import com.alibaba.fastjson.annotation.JSONField;
import com.moyuer.bsf.domain.model.Organ;
import org.springframework.util.ObjectUtils;

import javax.persistence.*;
import java.util.Date;

/**
 * 出入库单分录
 *
 * @author: 袁首京<yuanshoujing@gmail.com>
 * 16/4/13
 */
@Entity
@Table(name = "bill_store_entry")
public class StoreBillEntry extends BillEntry {

    private static final long serialVersionUID = 7527620918492078926L;

    @JSONField(serialize = false)
    @ManyToOne
    protected StoreBill owner;

    @JSONField(format = "yyyy-MM-dd HH:mm:ss")
    @Column(name = "create_time")
    private Date createTime = new Date();

    @ManyToOne
    private Organ store;  //收料，出料仓库

    @Transient
    private String storeId;     //仓库ID

    @Transient
    private String storeName;  //仓库名称
    @Transient
    private String sn; //所属单号

    @JSONField(format = "yyyy-MM-dd HH:mm:ss")
    @Transient
    private Date bizdate;

    @Transient
    private String biz_type;

    @Transient
    private String creator_name;

    @Column(name = "state")
    private Integer state;


    private Double checked = Double.valueOf(0.0);//已经复核多少

    @Transient
    private Integer ownerState;

    @Transient
    private String ownerRemark;

    @Transient
    private String goodsUnit;

    public Double getChecked() {
        return checked;
    }

    public void setChecked(Double checked) {
        this.checked = checked;
    }

    public Integer getState() {
        return state;
    }

    public void setState(Integer state) {
        this.state = state;
    }

    public StoreBill getOwner() {
        return owner;
    }

    public void setOwner(StoreBill owner) {
        this.owner = owner;
    }

    public String getSn() {
        return owner == null ? this.sn : owner.getSn();
    }

    public void setSn(String sn) {
        this.sn = sn;
    }

    public Date getBizdate() {
        return owner == null ? this.bizdate : owner.getBizdate();
    }

    public void setBizdate(Date bizdate) {
        this.bizdate = bizdate;
    }

    public Organ getStore() {
        return store;
    }

    public void setStore(Organ store) {
        this.store = store;
    }

    public String getStoreId() {
        if(!ObjectUtils.isEmpty(store)){
            this.storeId  = store.getId();
        }
        return storeId;
    }

    public void setStoreId(String storeId) {
        this.storeId = storeId;
    }

    public String getStoreName() {
        if(!ObjectUtils.isEmpty(store)){
            this.storeName  = store.getName();
        }

        return storeName;
    }

    public void setStoreName(String storeName) {
        this.storeName = storeName;
    }

    public String getBiz_type() {
        if (owner != null) {
            String type = "";
            switch (owner.getBiz_type()) {
                case -2:
                    type = "销售出库";
                    break;
                case -1:
                    type = "普通出库";
                    break;
                case 1:
                    type = "普通入库";
                    break;
                case 2:
                    type = "采购入库";
                    break;
            }
            return type;
        }
        return biz_type;
    }

    public void setBiz_type(String biz_type) {
        this.biz_type = biz_type;
    }

    public String getCreator_name() {
        return owner == null ? this.creator_name : owner.getCreatorName();
    }

    public void setCreator_name(String creator_name) {
        this.creator_name = creator_name;
    }

    public Integer getOwnerState() {
        return owner != null ? owner.getState() : this.ownerState;
    }

    public void setOwnerState(Integer ownerState) {
        this.ownerState = ownerState;
    }

    public Date getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    public String getOwnerRemark() {
        return this.owner != null ? this.owner.getRemark() : this.ownerRemark;
    }

    public void setOwnerRemark(String ownerRemark) {
        this.ownerRemark = ownerRemark;
    }

    public String getGoodsUnit() {
        return this.goods != null ? this.goods.getUnit() : this.goodsUnit;
    }

    public void setGoodsUnit(String goodsUnit) {
        this.goodsUnit = goodsUnit;
    }
}
